package com.powernode;

import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class test {
    public static void main(String[] args) {
        InetAddress ip;
        try {
            ip = InetAddress.getLocalHost();
            System.out.println("Current IP address : " + ip.getHostAddress());
            long startTime = System.nanoTime();
            NetworkInterface network = NetworkInterface.getByInetAddress(ip);
            byte[] mac = network.getHardwareAddress();
            long endTime = System.nanoTime();
            long duration = (endTime - startTime);
            double seconds = (double)duration / 1000000000.0;
            System.out.println("Duration: " +String.valueOf(seconds) + " seconds");
            System.out.print("Current MAC address : ");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mac.length; i++) {
                sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
            }
            System.out.println(sb.toString());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (SocketException e){
            e.printStackTrace();
        }
    }

    @Test
    void test1(){

        List<String> list = new ArrayList<String>();
        List<String> delete = new ArrayList<String>();
        list.add("http://192.168.100.41:9000/mall/product/10");
        list.add("http://192.168.100.41:9000/mall/product/12");
        list.stream().filter(img -> img.contains("http://192.168.100.41:9000")).map(img -> delete.add(img)).collect(Collectors.toList());
        delete.forEach(System.out::println);

    }
}
